﻿package com.best.oasis.settlement.biz.facade.security
{
	import com.best.oasis.flexbase.util.BeanUtils;
	import com.best.oasis.flexbase.util.tree.TreeNode;
	import com.best.oasis.settlement.biz.facade.base.SuperResponder;

	import com.best.oasis.settlement.biz.facade.base.OldBaseFacade;
	import com.best.oasis.settlement.common.Constants;
	import com.best.oasis.settlement.common.error.ErrorCode;
	import com.best.oasis.settlement.common.model.ModelLocator;
	import com.best.oasis.settlement.common.so.security.RoleGroupSO;
	import com.best.oasis.settlement.common.vo.admin.authentication.AuthenticationVO;
	import com.best.oasis.settlement.common.vo.security.RoleGroupVO;
	import com.best.oasis.settlement.common.vo.security.UserVO;
	import com.best.oasis.settlement.util.page.PageList;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	/**
	 * 角色管理类
	 * @author bl00064
	 * 
	 */	
	public class RoleGroupFacade extends OldBaseFacade
	{

		
		public function create(vo:RoleGroupVO, callback:Function=null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result != null){
						Alert.show("保存成功！");
						if(callback != null){
							callback();
						}
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("保存失败！" + event.fault.faultString);
				});
			
			delegate.create(vo).addResponder(responder);
		}
		public function getPageList(so:RoleGroupSO, result:PageList, callback:Function=null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var tResult:PageList = PageList(event.result);
					BeanUtils.copyProperties(result, tResult);
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取列表失败！" + event.fault.faultString);
				});
			
			delegate.getRoleGroupPageList(so).addResponder(responder);
		}
		public function remove(ids:ArrayCollection, callback:Function=null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var result:String = String(event.result);
					if(result==Constants.SUCCESS){
						Alert.show("删除角色成功！");
					}
					if(callback != null){
						callback();
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("删除失败！"+event.fault.faultString);
				});
		
			delegate.remove(ids).addResponder(responder);
		}
		public function update(vo:RoleGroupVO, pageList:PageList, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(pageList != null){
						var vo:RoleGroupVO = RoleGroupVO(event.result);
						BeanUtils.updateItem(pageList.list, vo);
					}
					if(callback != null){
						callback();
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("保存失败！" + event.fault.faultString);
				});
		
			delegate.update(vo).addResponder(responder);
		}
		/**
		 * 判断角色名是否存在
		 */
		public function roleNameExist(roleName:String, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result !=null){
						if(callback != null){
							callback(event.result as Boolean);
						}  
					}
				},
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取数据失败！" + event.fault.faultString);
				});
	
			delegate.roleNameExist(roleName).addResponder(responder);
		}
	}
}